import time
class Latency:
    '''
        延时处理
    '''
    def __init__(self):
        self.initStamp=0.0  #初始时间戳
        self.pStamp=0.0     #上一帧数据的时间戳
        self.val=0          #延迟数值
        self.rate=0         #数据频率
    def Refreshlatency(self,remoteStamp=0):
        '''
        返回当前时间和远程时间的差值
        :param remoteStamp:
        :return:
        '''
        localStamp=time.time()-self.initStamp
        self.val = int((localStamp*1000000.0-remoteStamp)/2000) #延时
        if 0.001<(time.time()-self.pStamp):
            self.rate=int(1.0/(time.time()-self.pStamp))    #数据频率
        self.pStamp=time.time()
    def Reset(self):
        self.initStamp=time.time()